package com.ruoyi.labour.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.labour.domain.LabourSlideshowFiles;
import com.ruoyi.labour.domain.vo.PageVo;
import com.ruoyi.labour.domain.vo.UpdateSlideshowVo;
import com.ruoyi.labour.domain.vo.UploadSlideshowVo;
import com.ruoyi.labour.enums.CustomerPhoneStatus;
import com.ruoyi.labour.mapper.SlideshowMapper;
import com.ruoyi.labour.service.SlideshowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: SlideshowServiceImpl
 * @Description:
 * @Author: Awen
 * @Date: 2023/5/13 14:58
 */
@Service
public class SlideshowServiceImpl implements SlideshowService {

    @Autowired
    private SlideshowMapper slideshowMapper;

    /**
     * 添加轮播图
     *
     * @param uploadSlideshowVo
     * @return
     */
    @Override
    public R addSlideshow(UploadSlideshowVo uploadSlideshowVo) {

        slideshowMapper.addSlideshow(uploadSlideshowVo);

        return R.ok("添加成功");
    }

    /**
     * 查询轮播图文件信息
     *
     * @param pageVo
     * @return
     */
    @Override
    public R selectSlideshow(PageVo pageVo) {

        PageHelper.startPage(pageVo.getPage(), pageVo.getSize());
        List<LabourSlideshowFiles> labourSlideshowFiles = slideshowMapper.selectSlideshow();
        PageInfo pageInfo = new PageInfo(labourSlideshowFiles);

        return R.ok(pageInfo);
    }

    /**
     * 修改轮播图
     *
     * @param updateSlideshowVo
     * @return
     */
    @Override
    public R updateSlideshow(UpdateSlideshowVo updateSlideshowVo) {
        int i = slideshowMapper.checkSlideshowIsExistByID(updateSlideshowVo.getId());
        if (i > 0) {
            slideshowMapper.updateSlideshow(updateSlideshowVo);

            return R.ok("修改成功");
        } else {
            return R.fail("轮播图不存在");
        }

    }

    /**
     * 删除轮播图
     *
     * @param id
     * @return
     */
    @Override
    public R deleteSlideshow(int id) {
        int i = slideshowMapper.checkSlideshowIsExistByID(id);
        if (i > 0) {
            slideshowMapper.deleteSlideshow(id);

            return R.ok("删除成功");
        } else {
            return R.fail("轮播图不存在");
        }

    }
}
